package com.iwhalecloud.bss.kite.cucc.web.service.accept.handler.attr;

import com.iwhalecloud.bss.kite.client.vo.scene.CommonAttrVO;
import com.iwhalecloud.bss.kite.common.util.KiteListUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.web.service.accept.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.base.entity.StaticAttrDO;
import com.ztesoft.bss.common.bo.UserInfo;
import com.ztesoft.bss.common.util.ContextUtil;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 是否总部收费类
 * Created by huanghaosheng on 2020/11/12 21:47
 */
@Service
public class CheckGroupFeeInfoHandler extends AbstractAttrHandler {

    @Override
    public void init(CommonAttrVO commonAttr) {
        UserInfo userInfo = ContextUtil.getLoginInfo().getUserInfo();
        List<StaticAttrDO> attrDOs = commonAttr.getAttrValues();
// 国际业务48只能选否，49只能选是
        if(KiteStringUtils.isNotEmpty(userInfo.getPostProvinceNbr())){
            if(userInfo.getPostProvinceNbr().startsWith("48")){
                attrDOs = attrDOs.stream().filter(attrDO -> KiteStringUtils.equalsAny(attrDO.getAttrValue(),"1_0000107","0")).collect(Collectors.toList());
                if(KiteListUtils.isNotEmpty(attrDOs)){
                    StaticAttrDO attrDO = attrDOs.get(0);
                    commonAttr.setValue(attrDO.getAttrValue());
                    commonAttr.setValueDesc(attrDO.getAttrValueDesc());
                    commonAttr.setAttrValues(attrDOs);
                }

            }else  if(userInfo.getPostProvinceNbr().startsWith("49")){
                attrDOs = attrDOs.stream().filter(attrDO -> KiteStringUtils.equalsAny(attrDO.getAttrValue(),"1_0000106","1")).collect(Collectors.toList());
                if(KiteListUtils.isNotEmpty(attrDOs)){
                    StaticAttrDO attrDO = attrDOs.get(0);
                    commonAttr.setValue(attrDO.getAttrValue());
                    commonAttr.setValueDesc(attrDO.getAttrValueDesc());
                    commonAttr.setAttrValues(attrDOs);
                }
            }
        }

        if (!KiteListUtils.isEmpty(attrDOs) && KiteStringUtils.isEmpty(commonAttr.getValue())) {
            attrDOs = attrDOs.stream().filter(attrDO -> KiteStringUtils.equalsAny(attrDO.getAttrValue(),"1_0000107","0")).collect(Collectors.toList());
            if(KiteListUtils.isNotEmpty(attrDOs)){
                StaticAttrDO attrDO = attrDOs.get(0);
                commonAttr.setValue(attrDO.getAttrValue());
                commonAttr.setValueDesc(attrDO.getAttrValueDesc());
                commonAttr.setAttrValues(attrDOs);
            }
        }
    }
}
